#include <iostream>
#include<bit>
#include<bitset> 
using namespace std;

int numberOfSteps(int num) {
    unsigned x = num;
    return x == 0 ? 0 : bit_idth(x) + __builtin_popcount(x) - 1;
}

int main() {
    int n;
    cin >> n;
    cout << numberOfSteps(n);
    return 0;
}

